// stores/user.ts
import { defineStore } from "pinia";
import { fetchMenuListApi } from "@/api/modules/menu";
import type { MenuItem } from '@/types/menu';

export const useMenuStore = defineStore("menu", {
  state: () => ({
    menuTree: [] as MenuItem[],
  }),
  getters:{},
  actions: {
   async fetchMenuTree() {
      return fetchMenuListApi().then((res:any) => {
        console.log(res);
        this.menuTree = res.data||res.data.data;
        return res.data;
      });
    },
  },
  persist: {
    enabled: true,
    strategies: [
      {
        key: "user",
        storage: localStorage,
      },
    ],
  },
});
